
(function ($, window, document) {

var oPage = {
	oThis: null,

	detail: null, // 详情
	approval: null, // 审批

	init: function () {
		this.initState();
		this.initEvent();
	},
	initState: function () {
		this.oThis = $('#applySeeWp');

		this.getDetail(); // 获取详情
	},
	initEvent: function () {

	},

	// 获取详情
	getDetail: function () {
		var _this = this;
		var dt = pb.storage.get('apply-detail');
		if (!dt) {
			return;
		}
		$.ajax({
			type: 'get',
			url: pb.api + '/baImageApply/get',
			data: {
				id: dt.id
			},
			success: function (res) {
				_this.detail = res.data.baImageApply;
				_this.approval = res.data.baApprovalOpinionVOList;

				_this.setDetailHtml(); // 根据detail设置内容
			}
		})
	},

	// 根据detail设置内容
	setDetailHtml: function () {
		if (!this.detail) {
			return;
		}
		this.oThis.find('.sqdh-text').html(this.detail.applyNo);
		this.oThis.find('.sqks-text').html(this.detail.deptName);
		this.oThis.find('.sqys-text').html(this.detail.doctorName);
		this.oThis.find('.sqsj-text').html(this.detail.applyTime);

		this.oThis.find('.yxxx-text').html(this.detail.imageName);
		this.oThis.find('.hzxm-text').html(this.detail.patientName);
		this.oThis.find('.hzxb-text').html(this.detail.sex);
		this.oThis.find('.hznl-text').html(this.detail.age);
		this.oThis.find('.hzmz-text').html(this.detail.outpatientCode);
		this.oThis.find('.hzzy-text').html(this.detail.hospitalizedCode);
		this.oThis.find('.hzjc-text').html(this.detail.equipmentDetail);
		this.oThis.find('.hzyx-text').html(this.detail.imageCode);
		this.oThis.find('.dzbw-text').html(this.detail.partName);
		this.oThis.find('.jbzd-text').html(this.detail.diagnosisMark);
		this.oThis.find('.dzly-text').html(this.detail.reasonMark);
		this.oThis.find('.yxsjlx-text').html(pb.getNameByCode(this.detail.imageTypeCode, pb.yxsjlxList));
	
		this.setApplyStep(); // 设置申请步骤
		this.setApprovalStep(); // 审批步骤
	},

	// 设置申请步骤
	setApplyStep: function () {
		var _this = this;
		var list = [
			{title: '新增申请', name: 'doctorName', time: 'applyTime'},
			{title: '院内审批', name: 'auditUserName', time: 'auditTime'},
			{title: '文件发送', name: 'fileSendUserName', time: 'fileSendTime'},
			{title: '文件接收', name: 'fileReceiveUserName', time: 'fileReceiveTime'},
			{title: '文件下载', name: 'downloadUserName', time: 'downloadTime'},
			{title: '制定计划', name: 'makeUserName', time: 'makeTime'},
			{title: '建模', name: 'modeUserStartName', time: 'modeActualTime'},
			{title: '制模', name: 'makeUserStartName', time: 'makeActualTime'},
			{title: '实物交付', name: 'matterReceiveUserName', time: 'matterReceiveTime'},
			{title: '文件交付', name: 'fileReceiveUserName', time: 'fileReceiveTime'},
		]
		var state = this.detail.makingState;
		var html = '';

		for (var i = 1; i <= list.length; i++) {
			var item = list[i-1];
			var type = 1, typeText = '待进行', text = '步骤的描述', icon = '';
			if (i <= state) {
				type = 3;
				typeText = '已完成';
				text = _this.detail[item.name] + '</br>' + _this.detail[item.time];
				icon = ' icon iconfont icongou';
			} else if (i == state+1) {
				type = 2;
				typeText = '进行中';
				icon = ' icon iconfont iconxia';
			}

			html += '<div class="item">' +
						'<span class="step-name">' + item.title + '</span>' +
						'<div class="icon-box">' +
							'<div class="type type' + type + '">' +
								'<span class="text' + icon + '">' + (type == 1 ? i : '') +  '</span>' +
								'<span class="left"></span>' +
								'<span class="right"></span>' +
							'</div>' +
						'</div>' +
						'<div class="text-box">' +
							'<span class="type">' + typeText + '</span>' +
							'<div class="descr"><p>' + text + '</p></div>' +
						'</div>' +
					'</div>';
		}
		this.oThis.find('.apply-step').html(html);
	},

	// 审批步骤
	setApprovalStep: function () {
		var _this = this;
		var html = '';
		for (var i = 0; i < this.approval.length; i++) {
			var item = this.approval[i];
			var isOk = !pb.isEmpty(item.approvalOpinionCode);
			html += '<div class="item ' + (isOk ? '' : 'not') + '">' +
						'<div class="icon iconfont ' + (isOk ? 'icongou' : 'iconxia') + '"></div>' +
						'<div class="title">' +
							'<span class="t1">' + item.nodeName +'</span>';
			if (!pb.isEmpty(item.approvalOpinionCode)) {
				html += '	<span class="result ' + (item.approvalOpinionCode == 1 ? 'success' : 'error') + '">' + item.approvalOpinionName + '</span>' +
						'</div>' +
						'<div class="sign">' +
							'<span class="name">' + item.approvalUserName + '</span>' +
							'<span>' + item.approvalTime + '</span>' +
						'</div>' +
						'<div class="idea">' +
							'<span class="label">审批意见：</span>' +
							'<span class="value">' + item.approvalOpinionDesc + '</span>';
			}
			html += '	</div>' +
					'</div>';
		}
		this.oThis.find('.approval-info .list').html(html);
	}

}


$(function () {
	oPage.init();
})

})($, window, document);

